// pages/lipei/lipei.js
const app=getApp();
Component({
  pageLifetimes: {
    show() {
      this.getTabBar().setData({
        selected: 0
      });
    }
  },
  data: {
    img_url:"",   //储存头像
    name:"",       //储存用户名
    vertical: false,
    autoplay: true,
    eventList: [],
    thingId:'',
    eventtime:'',
    actIndex:0,
    eventId:'',
    eventstate:"eyedetect",
    index:0,
    keyword:null,
    array: ["eyedetect","facepose","illegalact","gazetrack"],
    detail:'',
    num_person:'',
    datetime:'',
    chosenevent:0,
    behelpedID:''
  },
   
  methods:{
      /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that=this;

    that.data.name = app.globalData.userInfo.nickName
  
    wx.request({
      url: 'http://127.0.0.1:8000/list/listevent/',//开发者服务器地址
      data:{
        name:that.data.name,
        state:that.data.array[0],
      },
      method:"POST",
      success(res){
        console.log(res);
        that.setData({hosList:[]});
        var data
            for (var i = 0, len = res.data.retlist.length; i < len; i++){
            data =res.data.retlist[i]
            var hosList=that.data.hosList;
            var obj={
              id:data['id'],
              detail:data['detail'],
              datetime:data['datetime'],
              state:data['state'],
              show:true,
            };
            hosList.push(obj);
            that.setData({eventList:hosList})
          }
        }
      })
  },
  seeDetail:function(e){
    var that=this
    that.setData({
      eventtime:e.currentTarget.dataset.id
    })
    if(that.data.actIndex==0){
      var that=this;
      wx.request({
        url: 'http://127.0.0.1:8000/list/listdetail/',//开发者服务器地址
        data:{
          name:that.data.name,
          datetime:that.data.eventtime,
          state:that.data.eventstate,
        },
        method:"POST",
        success(res){
          wx.navigateTo({
            url: '../detail/detail?jsondata=' + encodeURIComponent(JSON.stringify(res.data))
          })          
          }
        })
    }else if(that.data.actIndex ==1){
      var that=this;
      wx.request({
        url: 'http://127.0.0.1:8000/list/listdetail1/',//开发者服务器地址
        data:{
          name:that.data.name,
          datetime:that.data.eventtime,
          state:that.data.eventstate,
        },
        method:"POST",
        success(res){
          wx.navigateTo({
            url: '../detail1/detail1?jsondata=' + encodeURIComponent(JSON.stringify(res.data))
          })          
          }
        })
    }else if(that.data.actIndex ==2){
      var that=this;
      wx.request({
        url: 'http://127.0.0.1:8000/list/listdetail2/',//开发者服务器地址
        data:{
          name:that.data.name,
          datetime:that.data.eventtime,
          state:that.data.eventstate,
        },
        method:"POST",
        success(res){
          wx.navigateTo({
            url: '../detail2/detail2?jsondata=' + encodeURIComponent(JSON.stringify(res.data))
          })          
          }
        })
    }else if(that.data.actIndex ==3){
    var that=this;
    wx.request({
      url: 'http://127.0.0.1:8000/list/listdetail3/',//开发者服务器地址
      data:{
        name:that.data.name,
        datetime:that.data.eventtime,
        state:that.data.eventstate,
      },
      method:"POST",
      success(res){
        wx.navigateTo({
          url: '../detail3/detail3?jsondata=' + encodeURIComponent(JSON.stringify(res.data))
        })          
        }
      })
  }
    
    
  },
    switchNav:function(e){
      console.log(e)
      this.setData({
        actIndex: e.target.dataset.current
      })
      var that=this
      if(that.data.actIndex==0){
        var that=this;
      wx.request({
        url: 'http://127.0.0.1:8000/list/listevent/',//开发者服务器地址
        data:{
          name:that.data.name,
          state:that.data.array[0],
        },
        method:"POST",
        success(res){
          console.log(res);
          that.setData({hosList:[]});
          var data
              for (var i = 0, len = res.data.retlist.length; i < len; i++){
              data =res.data.retlist[i]
              var hosList=that.data.hosList;
              var obj={
                id:data['id'],
                detail:data['detail'],
                datetime:data['datetime'],
                state:data['state'],
                show:true,
              };
              hosList.push(obj);
      
      that.setData({
        eventList:hosList,
        eventstate:"eyedetect"
      })
            }
          }
        })
      }else if(that.data.actIndex ==1){
        var that=this;
        wx.request({
          url: 'http://127.0.0.1:8000/list/listevent/',//开发者服务器地址
          data:{
            name:that.data.name,
            state:that.data.array[1],
          },
          method:"POST",
          success(res){
            console.log(res);
            that.setData({hosList:[]});
            var data
                for (var i = 0, len = res.data.retlist.length; i < len; i++){
                data =res.data.retlist[i]
                var hosList=that.data.hosList;
                var obj={
                  id:data['id'],
                  detail:data['detail'],
                  datetime:data['datetime'],
                  state:data['state'],
                  show:true,
                };
                hosList.push(obj);
                that.setData({
                  eventList:hosList,
                  eventstate:"facepose"
                })
              }
            }
          })
      }else if(that.data.actIndex ==2){
        var that=this;
        wx.request({
          url: 'http://127.0.0.1:8000/list/listevent/',//开发者服务器地址
          data:{
            name:that.data.name,
            state:that.data.array[2],
          },
          method:"POST",
          success(res){
            console.log(res);
            that.setData({hosList:[]});
            var data
                for (var i = 0, len = res.data.retlist.length; i < len; i++){
                data =res.data.retlist[i]
                var hosList=that.data.hosList;
                var obj={
                  id:data['id'],
                  detail:data['detail'],
                  datetime:data['datetime'],
                  state:data['state'],
                  show:true,
                };
                hosList.push(obj);
                that.setData({
                  eventList:hosList,
                  eventstate:"illegalact"
                })
              }
            }
          })
      }else if(that.data.actIndex ==3){
      var that=this;
      wx.request({
        url: 'http://127.0.0.1:8000/list/listevent/',//开发者服务器地址
        data:{
          name:that.data.name,
          state:that.data.array[3],
        },
        method:"POST",
        success(res){
          console.log(res);
          that.setData({hosList:[]});
          var data
              for (var i = 0, len = res.data.retlist.length; i < len; i++){
              data =res.data.retlist[i]
              var hosList=that.data.hosList;
              var obj={
                id:data['id'],
                detail:data['detail'],
                datetime:data['datetime'],
                state:data['state'],
                show:true,
              };
              hosList.push(obj);
              that.setData({
                eventList:hosList,
                eventstate:"gazetrack"
              })
            }
          }
        })
    }
  },
  },
  })
  